<template>
  <el-container class="homeContainer">
    <el-header>
      <div class="logo">
        <img src="../assets/logo.png" alt />
        <span>管理系统</span>
      </div>
      <el-button @click="logOut">退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu background-color="#545c64" text-color="#fff" active-text-color="#00b647">
          <el-submenu :index="item.id + ''" v-for="item in mentlist" :key="item.id">
            <template slot="title">
              <i :class="iconObj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item
              :index="subItem.id + ''"
              v-for="subItem in item.children"
              :key="subItem.id"
            >
              <i class="el-icon-menu"></i>
              <span>{{subItem.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>Main</el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      mentlist: [],
      iconObj: {
        '125' : 'iconfont icon-users',
        '103': 'iconfont icon-tijikongjian',
        '101': 'iconfont icon-shangpin',
        '102': 'iconfont icon-danju',
        '145': 'iconfont icon-baobiao'
      }
    }
  },
  created() {
    this.getMenuList()
  },
  methods: {
    logOut() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList() {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.mentlist = res.data
      console.log(res)
    }
  }
}
</script>
<style scoped>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  justify-content: space-between;
  display: flex;
  align-items: center;
}
.el-header .logo {
  width: 150px;
  height: 100%;
  padding-top: 10px;
}
.el-header .logo img {
  height: 80%;
  width: auto;
}
.el-aside {
  background-color: #d3dce6;
  color: #333;
  height: 100%;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

.homeContainer {
  height: 100%;
}
</style>
